<html>
<head>
<title>DIGI - Infomat</title>
<meta http-equiv="Content-Type"
	content="text/html; charset=windows-1251">
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
.style1 {
	width: 35%;
}
</style>
<script type="text/javascript">
function isIP(strIP) 
{ 
    var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g;
    if(re.test(strIP)) 
    { 
        if( RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256) return true; 
    } 
    return false; 
}

function isMac(strMac) 
{ 
    var re=/^([0-9A-Fa-f]{2})(-[0-9A-Fa-f]{2}){5}|([0-9A-Fa-f]{2})(:[0-9A-Fa-f]{2}){5}/;
    if(re.test(strMac)) 
    { 
        return true; 
    } 
    return false; 
}

function isNum(str)
{
    var reg=/^[0-9]*$/;
    
    if(!reg.test(str))
        return false;
    else
        return true;
}

function chkForm()
{
    var flag=true;
    var txtIP=document.getElementById("txtIP");
    var lblIPMsg=document.getElementById("lblIPMsg");
    var txtGateway=document.getElementById("txtGateway");
    var lblGatewayMsg=document.getElementById("lblGatewayMsg");
    var txtMac=document.getElementById("txtMac");
    var lblMacMsg=document.getElementById("lblMacMsg");
    var txtUdpPort=document.getElementById("txtUdpPort");
    var lblPortMsg=document.getElementById("lblPortMsg");
    
    lblIPMsg.innerHTML="";
    lblGatewayMsg.innerHTML="";
    lblMacMsg.innerHTML="";
    lblPortMsg.innerHTML="";
    
    if(txtIP.value=="" || !isIP(txtIP.value))
    {
        flag=false;
        lblIPMsg.innerHTML="IP address is invalid.";
    }
    
    if(txtGateway.value=="" || !isIP(txtGateway.value))
    {
        flag=false;
        lblGatewayMsg.innerHTML="Gateway is invalid.";
    }
    
    if(txtMac.value=="" || !isMac(txtMac.value))
    {
        flag=false;
        lblMacMsg.innerHTML="Mac is invalid.";
    }
    
   // if(txtUdpPort.value=="" || !isNum(txtUdpPort.value))
   // {
   //     flag=false;
   //     lblPortMsg.innerHTML="Port is invalid.";
   // }
    
    return flag;
}
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="text-align: center">
    <?php
	include "xudpd.php";
	include "xutility.php";
	$xUdpd = new XUdpd ();
    $xUtility = new XUtility();    
    if (!empty($_POST)) {
       //echo "<pre>";
       //print_r($_POST);
       //echo "</pre>";
       $btn = $_POST['btn'];
            
	   switch ($btn)
	   {
	    case "save":
		    $in_ip = $_POST['txtIP'];
			 $xUdpd->setIp($in_ip);
			 $in_gateway = $_POST['txtGateway'];
			 $xUdpd->setGateway($in_gateway);
			 $in_mac = $_POST['txtMac'];
			 $xUdpd->setMac($in_mac);
			// $in_port = $_POST['txtUdpPort'];
			// $xUdpd->setUdpPort($in_port);
			$xUdpd->writeUdpd();
			break;
		case "reboot":
			$xUtility->reboot();
			break;
	   }
	   
       //if ($btn == "save") {
       //    echo "doing save <br/>";
       //    echo $in_ip;
       //    $xUdpd->writeUdpd();
      //  } 
    }
	?>
<form name="maintenanceForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="100%">
	<tr>
		<td align="center">
            <table width="780" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>
                    	<table border="0" bgcolor="#FFFFFF" width="100%">
                        	<tr>
                            	<td rowspan="2" width="20%"><img src="images/logo.png" alt="logo"></td>
                            </tr>
                            
                            <tr valign="bottom"  align="center">
                                <td ><a href="home.php"><img style="border-width:0px;" src="images/btn_home.png" alt="home"></a></td>
                                <td ><a href="network.php"><img style="border-width:0px;" src="images/btn_network.png" alt="Network Setting"></a></td>
                                <td><a href="update.php"><img style="border-width:0px;" src="images/btn_update.png" alt="Update Firmware"></a></td>
                               <td><a href="setting.php"><img style="border-width:0px;" src="images/btn_setting.png" alt="setting"></a></td>
                              <td><a href="filemanage.php"><img style="border-width:0px;" src="images/btn_filemanage.png" alt="File Manage"></a></td>
                            </tr>
                        </table> 
                   </td>
                </tr>
          		
                <tr>
                    <td colspan="2">
						<table border="0" cellspacing="0" cellpadding="0"></table>
					</td>
				</tr>

				<tr>
					<td colspan="2" valign="middle" bgcolor="#FFFFFF">
						<table width="780px" border="0" cellspacing="0" cellpadding="0" class="form_table">
							<tr>
                                <td width="3%" style="">&nbsp;</td>
								<td  width="20%" valign="middle" class="name"><strong class="green-text">Network Setting</strong></td>
								<td width="50%">&nbsp;</td>
                                <td width="30%" style="">&nbsp;</td>
							</tr>

							<tr>
								<td style="">&nbsp;</td>
								<td valign="middle" width="10%" ><strong>IP</strong></td>
								<td>
									<label id="lblIP">
	                        		<?php
									$ip = $xUdpd->getIp();
									?>
									</label> 
									<input type="text" id="txtIP" name="txtIP" value="<?php echo $ip; ?>" />
									<label id="lblIPMsg" style="color:Red;"></label>
                                </td>
                                <td rowspan="4" style=""><p class="red-text-regular">The new settings will be effective since next reboot Infomat.</p>
                                <p>&nbsp;</p></td>
								
							</tr>
							<tr>
								<td style="">&nbsp;</td>
								<td valign="middle" class="name" width="10%"  ><strong>Gateway</strong></td>
								<td> 
									<label id="lblGateway">
										<?php
										$gateway = $xUdpd->getGateway ();
										?>
                                    </label>
									<input type="text" id="txtGateway" name="txtGateway" value="<?php echo $gateway; ?>"/>
									<label id="lblGatewayMsg" style="color:Red;"></label>
								</td>
                            </tr>
											
							<tr>
								<td style="">&nbsp;</td>
								<td valign="middle" class="style1" style="width: 10%"><strong>Mac</strong></td>
								<td>
                                    <label id="lblMac">
	                        			<?php
										$mac = $xUdpd->getMac ();
										?>
									</label> 				
									<input type="text" id="txtMac" value="<?php echo $mac; ?>" name="txtMac" />
									<label id="lblMacMsg" style="color:Red;"></label>
								</td>
							</tr>
											
							<tr>
								<td style="">&nbsp;</td>
								<td valign="middle" class="name" style="width: 10%"><strong>UDP Port</strong></td>
								<td>
                                    <label id="lblUdpPort">
									
                                    </label>
                                    <label id="lblPortMsg" style="color:Red;"></label>
								5042</td>
                            </tr>
                            
							<tr>
								<td></td>
								<td width="10%" ><input type="submit" name="btn" value="save" id="save" onClick="return chkForm();" /></td>
                                <td >&nbsp;</td>
                                <td width="20%" align="right" >
                                <input type="submit" name="btn" value="reboot" id="reboot" onClick="return chkForm();" />
                                </td>
                               
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td></td>
				</tr>
				<tr>
					<td colspan="2" align="center" class="white-text">
                        <table width="100%" border="0" cellspacing="0" cellpadding="10">
							<tr>
								<td align="center" class="white-text">Copyright &copy; Teraoka Weigh System. All Rights Reserved</td>
							</tr>
						</table>
					</td>
				</tr>

			</table>
		</td>
	</tr>
</table>
</form>
</body>
</html>

